import { log } from "node:console";
import React, { Component } from "react";

export default class App extends Component {
  state = {
    name: "张三",
  };
  //创建ref属性
  inpRef = React.createRef<HTMLInputElement>();

  render() {
    return (
      <div>
        <h1>父组件-{this.state.name}</h1>
        {/* 2.设置ref，相当于一个id标识符 */}
        <input
          ref={this.inpRef}
          type="text"
          placeholder="请输入名字"
          onClick={() => {
            // 3.获取被标记的输入框
            console.log(this.inpRef.current?.value);
          }}
        />
      </div>
    );
  }
}
